/**
 * 旅游包车分析
 */

var vehicle;
var enterprise;
$(function(){
	areaanalyzesAL.init();
});

var areaanalyzesAL = {
	param: {},
	init: function(){
		var me = this;
		me.id="";
		me.text="";
		me.initQueryTime();
		me.initweek();
		me.initEmptyList();
		me.loadTableTitle();
		me.bindQuery();
		me.DoubleBarChart=me.initDoubleBarChart();
		me.PieChart=me.initPieChart();
		//me.queryTable();
	},


	/**
	    * 事件触发查询
	    */
	    bindQuery: function () {
	    	var me = this;
	    	$("#typeSelDiv").on('change',function(){
				var level = $("#selectTypeSel").val();
				me.initAreaList(level);
			});
	    	
	        $("#exportExcel").bind('click', function () {
	        	me.exportComfirm();
	        });
	        $("#confirmExport").click(function () {
	        	me.exportComfirm();
	        })
	        $('#queryBtn').click(function () {
	        	var	areaIds = $("#queryArea").combotree("getValues");
	            if(areaIds.length==0){
	            	global.ajaxLoading.pop("至少选择一个区域", false, 1000);
	                return;
	            }
	            me.queryTable('','select');
	        });
	    },
	    
	  //初始化周维度
	  initweek : function(){
		  $.ajax({
	    		type : 'post',
	    		url : appCtx + "base/report/PlatformAnalyzes/queryweek.html",
	    		cache : false,
	    		dataType : "JSON",
	    		success : function(data) {
	    			if(data!=null&&data!=''){
	    				$.each(data,function(entryIndex,entry) {
	    					$("#week").append("<option value='"+entry.value+"'>"+entry.text+"</option>");
	    				});				
	    			}
	    		}
		  });
	},
    getColumn1:function(){
    	return [{
            display : '区域名称',
            name : 'area_name',
            width : 25,
            sortable : false,
            align : 'left'
        },{
            display : '车辆总数',
            name : 'vehicle_count',
            width : 15,
            sortable : false,
            align : 'left',
            showTitle : 'vehicle_count'
        },{
            display : '入网数',
            name : 'vehicle_access_count',
            width : 15,
            sortable : false,
            align : 'left',
            showTitle : 'vehicle_access_count'
        },{
            display : '入网率(%)',
            name : 'vehicle_access_rate',
            width : 15,
            sortable : false,
            align : 'left',
            paramcolnames:['vehicle_access_rate'],
            handlefunction:function(paramcolnames){
            	var handleStr =Math.round(paramcolnames*Math.pow(10,2))/Math.pow(10,2);	
        		return handleStr;
            }
        },{
            display : '上线数',
            name : 'vehicle_online_count',
            width : 15,
            sortable : false,
            align : 'left',
        },{
            display : '上线率(%)',
            name : 'vehicle_online_rate',
            width : 15,
            sortable : false,
            align : 'left',
            paramcolnames:['vehicle_online_rate'],
            handlefunction:function(paramcolnames){
            	var handleStr =Math.round(paramcolnames*Math.pow(10,2))/Math.pow(10,2);	
        		return handleStr;
            }
        }]
    },
 
    getColumn2:function(){
    	return [{
            display : '区域名称',
            name : 'areaName',
            width : 16,
            sortable : false,
            align : 'left',
            paramcolnames:['areaName'],
            handlefunction:function(areaName){
            	var handleStr="<span style='color:#2a5ab1;width:32%;font-weight:900;display:inline-block;' >"+areaName+"</span>";
        		return handleStr;
            }
        },{
            display : '班线客运',
            name : 'regularBus',
            width : 28,
            sortable : false,
            align : 'center',
            paramcolnames:['regularBus'],
            handlefunction:function(regularBus){
            	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>-</span>";
            	if(regularBus!=''&&regularBus!=null&&regularBus!=undefined){
                	var arr = regularBus.split('|');
                	if(arr[0]=='车辆总数'){
                		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
                	}else{
                    	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
                	}
            	}
        		return handleStr;
            }
        },{
            display : '旅游客运',
            name : 'touringCar',
            width : 28,
            sortable : false,
            align : 'center',
            paramcolnames:['touringCar'],
            handlefunction:function(touringCar){
            	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>-</span>";
            	if(touringCar!=''&&touringCar!=null&&touringCar!=undefined){
                	var arr = touringCar.split('|');
                	if(arr[0]=='车辆总数'){
                		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
                	}else{
                    	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
                	}
            	}
        		return handleStr;
            }
        },{
            display : '危运车辆',
            name : 'dangerCar',
            width : 28,
            sortable : false,
            align : 'center',
            paramcolnames:['dangerCar'],
            handlefunction:function(dangerCar){
            	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>-</span>";
            	if(dangerCar!=''&&dangerCar!=null&&dangerCar!=undefined){
                	var arr = dangerCar.split('|');
                	if(arr[0]=='车辆总数'){
                		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
                	}else{
                    	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
                	}
            	}
        		return handleStr;
            }
        }]
    },
    getColumn3:function(){
    	return [{
            display : '区域名称',
            name : 'area_name',
            width : 15,
            sortable : false,
            align : 'left'
        },{
            display : '报警车辆数',
            name : 'alarm_vehicle_count',
            width : 9,
            sortable : false,
            align : 'left',
            showTitle : 'alarm_vehicle_count'
        },{
            display : '报警率(%)',
            name : 'alert_rate',
            width : 9,
            sortable : false,
            align : 'left',
            showTitle : 'alert_rate',
            paramcolnames:['alarm_vehicle_count','vehicle_access_count'],
            handlefunction:function(alarm_vehicle_count,vehicle_access_count){
            	var handleStr;
            	if(vehicle_access_count==0){
            		handleStr="0"
            	}else{
                	handleStr =Math.round(((alarm_vehicle_count/vehicle_access_count)*100)*Math.pow(10,2))/Math.pow(10,2);
            	}
        		return handleStr;
            }
        },{
            display : '报警条数',
            name : 'alarm_count',
            width : 9,
            sortable : false,
            align : 'left',
            showTitle : 'alarm_count'
        },{
            display : '处理条数',
            name : 'alarm_processed',
            width : 9,
            sortable : false,
            align : 'left',
        },{
            display : '处警率(%)',
            name : 'alarm_processed_rate',
            width : 9,
            sortable : false,
            align : 'left',
            paramcolnames:['alarm_processed','alarm_count'],
            handlefunction:function(alarm_processed,alarm_count){
//            	console.log(alarm_processed);
            	var handleStr;
            	if(alarm_count==0){
            		handleStr="0"
            	}else{
                	handleStr =handleStr =Math.round(((alarm_processed/alarm_count)*100)*Math.pow(10,2))/Math.pow(10,2);
            	}
        		return handleStr;
            }
        },{
            display : '超速报警条数',
            name : 'overspeed_count',
            width : 10,
            sortable : false,
            align : 'left'
        },{
            display : '平均超速次数',
            name : 'overspeed_count_avg',
            width : 10,
            sortable : false,
            align : 'left',
            paramcolnames:['overspeed_count','vehicle_online_count'],
            handlefunction:function(overspeed_count,vehicle_online_count){
            	var handleStr
            	if(vehicle_online_count==0){
            		handleStr ="0";
            	}else{
            		handleStr = Math.round((overspeed_count/vehicle_online_count)*100)/Math.pow(10,2);
            	}
        		return handleStr;
            }
        },{
            display : '疲劳驾驶时长(分钟)',
            name : 'tired_duration',
            width : 10,
            sortable : false,
            align : 'left',
            paramcolnames:['tired_duration'],
            handlefunction:function(tired_duration){
            	var handleStr;
            	handleStr =Math.floor(tired_duration/60);
        		return handleStr;
           }
        },{
            display : '平均疲劳驾驶时长(分钟)',
            name : 'outTime',
            width : 10,
            sortable : false,
            align : 'left',
            paramcolnames:['tired_duration','vehicle_online_count'],
            handlefunction:function(tired_duration,vehicle_online_count){
            	var handleStr;
            	if(vehicle_online_count==0){
            		handleStr ="0";
            	}else{
            		handleStr =Math.round(((tired_duration/vehicle_online_count)/60)*Math.pow(10,2))/Math.pow(10,2);
            	}	
        		return handleStr;
            }
        }]
    },
    getColumn4:function(){
    	return [{
            display : '区域名称',
            name : 'area_name',
            width : 13,
            sortable : false,
            align : 'left'
        },{
            display : '异常车辆数',
            name : 'exception_vehicle_count',
            width : 12,
            sortable : false,
            align : 'left',
            showTitle : 'exception_vehicle_count'
        },{
            display : '异常率(%)',
            name : 'exception_rate',
            width : 11,
            sortable : false,
            align : 'left',
            showTitle : 'exception_rate',
            paramcolnames:['exception_vehicle_count','vehicle_online_count'],
            handlefunction:function(exception_vehicle_count,vehicle_online_count){
            	var handleStr=exception_vehicle_count/vehicle_online_count;
            	if(vehicle_online_count==0){
            		handleStr ="0";
            	}else{
            		handleStr =Math.round(((handleStr>1?1:handleStr)*100)*Math.pow(10,2))/Math.pow(10,2);
            	}	
        		return handleStr;
            }
        },{
            display : '速度>160条数',
            name : 'speed_160_count',
            width : 12.5,
            sortable : false,
            align : 'left',
            showTitle : 'speed_160_count'
        },{
            display : '经纬度异常条数',
            name : 'location_exception_count',
            width : 13.5,
            sortable : false,
            align : 'left',
        },{
            display : '时间异常条数',
            name : 'gpstime_exception_count',
            width : 12.5,
            sortable : false,
            align : 'left'
        },{
            display : '方向异常条数',
            name : 'head_exception_count',
            width : 12.5,
            sortable : false,
            align : 'left'
        }
        ,{
            display : '异常数据比率(%)',
            name : 'exception_contrast_rate',
            width : 13.5,
            sortable : false,
            align : 'left',
            paramcolnames:['exception_track_count','track_normal'],
            handlefunction:function(exception_track_count,track_normal){
            	var handleStr;
            	if(track_normal==0){
            		handleStr ="0";
            	}else{
            		handleStr = handleStr =Math.round(((exception_track_count/(Number(track_normal)+Number(exception_track_count)))*100)*Math.pow(10,2))/Math.pow(10,2);
            	}	
        		return handleStr;
            }
        }]
    },
    
    loadTableTitle:function(){
    	$("#objTable1").flexigrid({
	            dataType : 'json',
	            colModel :this.getColumn1() ,
	            usepager : false,// 是否分页，默认为true。
	            singleSelect:true,
	            height:240,
	            widthType:'%',
	            width:$('#chartMillage1').width(),
	            rp : 100000,
	            onSelectRow:function(row){
	            	showShadowRegion(row.area_id);
	            }
	         });
    	$("#objTable2").flexigrid({
            dataType : 'json',
            colModel :this.getColumn2() ,
            usepager : false,// 是否分页，默认为true。
            singleSelect:true,
            height:240,
            widthType:'%',
            width:$('#chartMillage2').width(),
            rp : 100000
         });
    	$("#objTable3").flexigrid({
            dataType : 'json',
            colModel :this.getColumn3() ,
            usepager : false,// 是否分页，默认为true。
            singleSelect:true,
            height:240,
            widthType:'%',
            width:$('#chartMillage3').width(),
            rp : 100000
         });
    	$("#objTable4").flexigrid({
            dataType : 'json',
            colModel :this.getColumn4() ,
            usepager : false,// 是否分页，默认为true。
            singleSelect:true,
            height:240,
            widthType:'%',
            width:$('#chartMillage4').width(),
            rp : 100000,
            onSelectRow:function(row){
            	areaanalyzesAL.queryTable(row.area_id,"PieChart");
            }
         });
    },
    
	
	initPieChart: function(){
		var me = this;
		option = {
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    
			    legend: {
			        orient: 'vertical',
			        left: 'left',
			        data: []
			    },
			    series : [
			  	        {
			  	            name: '异常统计',
			  	            type: 'pie',
			  	            radius: ['45%', '75%'],
			  	            center: ['50%', '50%'],
			  	            avoidLabelOverlap: true,
			  	            label: {
			  	                normal: {
			  	                    show: true,
			  	                    formatter: '{b}',
			  	                    backgroundColor: '#eee',
			  	                    borderColor: '#aaa',
			  	                    borderWidth: 1,
			  	                    borderRadius: 4,
			  	                },
			  	                emphasis: {
			  	                    show: true,
			  	                    position:'inside',
			  	                    textStyle: {
			  	                        fontSize: '15',
			  	                        fontWeight: 'bold'
			  	                    }
			  	                }
			  	            },
			  	            labelLine: {
			  	                normal: {
			  	                    show: true,
			  	                },
			  	            },
			  	            data:[]
			  	        }
			  	    ],
			    color: ['rgb(249,124,37)','rgb(74,178,191)','rgb(134,218,179)','rgb(97,160,168)']
			};
		 var PieChart = echarts.init(document.getElementById('pieChart'));
		 PieChart.setOption(option);
         window.onresize = PieChart.resize;
         return {
         	refash : function(option){
         		PieChart.setOption(option);
         	},
         	option : option,
         	pieChartDom : PieChart
         };
	},
	
	initDoubleBarChart: function(){
	var me = this;
	option = {
		    tooltip: {
		        trigger: 'axis',
		        formatter: '{b0}<br />{a0}: {c0}%',
		        axisPointer: {
		            type: 'cross',
		            crossStyle: {
		                color: '#999'
		            }
		        }
		    },
		    grid:{
		    	top:'50px',
		    	bottom:'8%',
		    	right:45,
		    },
		    legend: {
		    	data:['入网率','上线率']
		    },
		    xAxis: [
		        {
		            type: 'category',
		            data: []
		        }
		    ],
		    yAxis: [
		        {
		            type: 'value',
		            name: '入网率',
		            min: 0,
		            max: 100,
		            interval: 20,
		            axisLabel: {
		                formatter: '{value} %'
		            }
		        },
		        {
		            type: 'value',
		            name: '上线率',
		            min: 0,
		            max: 100,
		            interval: 20,
		            axisLabel: {
		                formatter: '{value} %'
		            }
		        }
		    ],
		    series: [
		        {
		            name:'入网率',
		            type:'bar',
		            barMaxWidth:'40px',
		            itemStyle: {normal: {color:'#27727b'}},
		            data:[]
		        },
		        {
		            name:'上线率',
		            type:'bar',
		            barMaxWidth:'40px',
		            itemStyle: {normal: {color:'#e87c25'}},
		            data:[]
		        }
		    ]
		};
        var mydoubleChart = echarts.init(document.getElementById('doubleBarChart'));
        mydoubleChart.setOption(option);
        window.onresize = mydoubleChart.resize;
        return {
        	refash : function(option){
        		mydoubleChart.setOption(option);
        	},
        	option : option,
        	barChartDom : mydoubleChart
        };        
	},

	initAreaList:function(level,area_name,area_id){
		var me = this;
		//debugger;
		$('#queryArea').combotree({
			url:appCtx + "system/common/queryAreaName.html?level="+level,
			valueField: 'id',
            textField: 'text',
            method: 'post',
            multiple:true,
            editable : false,
            collapseAll : true,
            onSuccess : function(data){
            },            
            loadFilter: function(data){
            	 //data.unshift({ id: '', text: '请选择所属区域'});
            	 if(data.length>0){
            		 me.id=data[0].id;
            		 me.text=data[0].text;
            	 }
                 return data;
    		},
    		onLoadSuccess: function (data) {
    			$('#queryArea').combotree('tree').tree("collapseAll");
    			if(me.text!=null && me.text!=""){
    				$('#queryArea').combotree('setText',me.text);
    				$('#queryArea').combotree('setValue',me.id);
    				$('#queryBtn').click();
    			}else{
    				$('#queryArea').combotree('setText','请选择所属区域');
    			}
         	}
			
		});
	},
	
	initEmptyList: function(){
		var me=this;
    	$.ajax({
    		type : 'post',
    		async : true,
    		url : appCtx + "system/common/queryLevel.html",
    		cache : false,
    		dataType : "JSON",
    		success : function(data) {			
    			if(data){
    				$('#typeSelDiv').html("<select class='query-select' id='selectTypeSel'></select>");
    				var selectStr="";
    				for(var i=0;i<data.length;i++){
    					selectStr+="<option value='"+data[i].id+"'>"+data[i].text+"</option>";
    				}
    				$('#selectTypeSel').html(selectStr);
    				/*$("#selectTypeSel").select2({
    					minimumResultsForSearch: -1
    				});*/
    			}
    			me.initAreaList(data[0].id);
    		}
    	});
    },

    queryTable:function(areaId,name){
    	// 区域下拉多选ID
    	if(name=='select' || name=='PieChart'){
    		var	areaIds = $("#queryArea").combotree("getValues");
    	}
    	var level = $("#selectTypeSel").val();
    	if(pageAreaLevel!=null && pageAreaLevel!=""){
    		level = pageAreaLevel;
    		$("#selectTypeSel").val(pageAreaLevel);
    	}
    	if(pageAreaId!=null && pageAreaId!=""){
    		var areaId = pageAreaId;
    	}
    	var veidoo = $("#veidoo").val();
    	if(veidoo=='day'){
    		analyse_date = $("#day").val();
    	}else if(veidoo=='week'){
    		analyse_date = $("#week").val();
    	}else if(veidoo=='month'){
    		analyse_date = $("#month").val();
    	}
    	var me = this;
    	$.ajax({
    		url:appCtx+"base/report/AreaAnalyzes/queryAreaAnalyzes.html",
    		type:"post",
			async : true,
			cache : false,
    		data:{
    			veidoo:veidoo,
    			analyse_date:analyse_date,
    			areaId:areaId,
    			level:level,
    			areaIds:areaIds
    		},
    		dataType:"json",
    		success:function(data){
    			if(name=='PieChart'){
    		     	showpieChart(data.listAnalyzes[0]);
    			}else{
        			if(data.listAnalyzes.length==0){
        				var dataRows= {
        			     		rows:'',
        			     		total:0,
        			     		page:1
        			     	};
        				$("#objTable1").flexAddData(dataRows);
        		     	$("#objTable2").flexAddData(dataRows);
        		     	$("#objTable3").flexAddData(dataRows);
        		     	$("#objTable4").flexAddData(dataRows);
        		     	$("#objTable5").flexAddData(dataRows);
        		     	/*初始化饼图*/
        		     	showpieChart('');
        		     	showShadowRegion('');
        		     	if(pageAreaId!=null && pageAreaId!=""){
        		     		$('#queryArea').combotree('setText',pageAreaName);
        		     		$("#queryArea").combotree("setValue",pageAreaId);
        		     	}
        		     	
        		     	pageAreaId='';
        		     	pageAreaName='';
        		     	pageVeidoo='';
        		     	pageAnalyse_date='';
        			}else{
    					/*给所有table赋值*/
        				var dataRows= {
        			     		rows:data.listAnalyzes,
        			     		total:data.listAnalyzes.length,
        			     		page:1
        			     	};
        		     	var list= {
        			     		rows:data.list,
        			     		total:data.list.length,
        			     		page:1
        			     	};
        		     	$("#objTable1").flexAddData(dataRows);
        		     	$("#objTable2").flexAddData(list);
        		     	$("#objTable3").flexAddData(dataRows);
        		     	$("#objTable4").flexAddData(dataRows);
        		     	$("#objTable5").flexAddData(dataRows);
        		     	/*初始化饼图*/
        		     	showpieChart(data.listAnalyzes[0]);
        		     	showShadowRegion(data.listAnalyzes[0].area_id);
        		     	if(pageAreaId!=null && pageAreaId!=""){
        		     		$('#queryArea').combotree('setText',pageAreaName);
        		     		$("#queryArea").combotree("setValue",pageAreaId);
        		     	}
        		     	
        		     	pageAreaId='';
        		     	pageAreaName='';
        		     	pageVeidoo='';
        		     	pageAnalyse_date='';
        			}
    			}
    		}
    	});
    },
    /*exportExcel: function(){
    	var total = $("#objTable1").getOptions().total;
		if (total == 0) {
	          global.ajaxLoading.pop("无导出数据", false, 2000);
	          return;
	    }
		$(window.parent.document).find("#exportModal").modal("show");
	},	*/
	/**
     * 导出
     */
    exportComfirm: function () {
    	var me = this;
    	var	areaIds = $("#queryArea").combotree("getValues");
    	var veidoo = $("#veidoo").val();
    	var analyse_date = null;
    	if(veidoo=='day'){
    		analyse_date = $("#day").val();
    	}else if(veidoo=='week'){
    		analyse_date = $("#week").val();
    	}else if(veidoo=='month'){
    		analyse_date = $("#month").val();
    	}
        var total = $("#objTable1").getOptions().total;
        if (total == 0) {
	          global.ajaxLoading.pop("无导出数据", false, 2000);
	          return;
	    }
        //总记录数
        window.parent.global.ajaxLoading.pop("正在导出,请稍后.....", true, 2000);
        var header1 = JSON.stringify(me.getColumn1());
    	var header2 = JSON.stringify(me.getColumn2());
    	var header3 = JSON.stringify(me.getColumn3());
    	var header4 = JSON.stringify(me.getColumn4());
        
    	var headerbox1 = JSON.parse(header1);
    	var headerbox2 = JSON.parse(header2);
    	var headerbox3 = JSON.parse(header3);
    	var headerbox4 = JSON.parse(header4);
    	
    	var headerWidth1 = $("#objTable1").width();
    	for(var i=0;i<headerbox1.length;i++){
    		headerbox1[i].width = Math.ceil(headerWidth1*1.5/ 100 * headerbox1[i].width);
    	}
    	var headerWidth2 = $("#objTable2").width();
    	for(var i=0;i<headerbox2.length;i++){
    		headerbox2[i].width = Math.ceil(headerWidth2 / 100 * headerbox2[i].width);
    	}		
    	var headerWidth3 = $("#objTable3").width();
    	for(var i=0;i<headerbox3.length;i++){
    		headerbox3[i].width = Math.ceil(headerWidth3 / 100 * headerbox3[i].width);
    	}		
    	var headerWidth4 = $("#objTable4").width();
    	for(var i=0;i<headerbox4.length;i++){
    		headerbox4[i].width = Math.ceil(headerWidth4 *1.5/ 100 * headerbox4[i].width);
    	}
    	
    	headerbox1.splice(headerbox1.length,1);
    	headerbox2.splice(headerbox2.length,1);
    	headerbox3.splice(headerbox3.length,1);
    	headerbox4.splice(headerbox4.length,1);
    	
    	var headerend1 = JSON.stringify(headerbox1);
    	var headerend2 = JSON.stringify(headerbox2);
    	var headerend3 = JSON.stringify(headerbox3);
    	var headerend4 = JSON.stringify(headerbox4);
      //图片
		 var imageUrl = me.DoubleBarChart.barChartDom.getDataURL({
				type: 'png',
			    pixelRatio: 1
		}); 
		 var imageUrl2 = me.PieChart.pieChartDom.getDataURL({
				type: 'png',
			    pixelRatio: 1
		}); 
		var imgsrcList=new Array();
		imgsrcList.push(imageUrl);
		imgsrcList.push(imageUrl2);
		var imgsrc= $.toJSON(imgsrcList);
		//表头
		var colModelList = new Array();
        colModelList.push(headerend1);
        colModelList.push(headerend2);
        colModelList.push(headerend3);
        colModelList.push(headerend4);
        var colModel = $.toJSON(colModelList);
        var sheetNames=["区域车辆统计","区域行业统计","区域报警统计","区域异常统计"];
        var paramsGrid = {
           colModel: colModel,
            title: "区域分析统计表",
            imgsrc: imgsrc,
            veidoo:veidoo,
			analyse_date:analyse_date,
			areaIds:areaIds,
			sheetNames:$.toJSON(sheetNames),
			level:$("#selectTypeSel").val()
        };
        post(appCtx + "base/report/AreaAnalyzes/exportAreaAnalyzes.html", paramsGrid);
    },
    
    initQueryTime:function(){//默认时间
        var todayDate = new Date();
        var todayDateStr=todayDate.getFullYear()+"-"+(todayDate.getMonth()+1)+"-"+todayDate.getDate();  
        	
        var beforeDate = new Date(todayDate-86400000*1); //前一天
	    var yyyy = beforeDate.getFullYear(), mm = (beforeDate.getMonth() + 1).toString(), dd = beforeDate.getDate().toString();
	    if (mm.length == 1) {
	        mm = '0' + mm;
	    }
	    if (dd.length == 1) {
	        dd = '0' + dd;
	    }
        $("#day").val(yyyy + '-' + mm + '-' + dd);
        $("#month").val(yyyy + '-' + mm );
      }
	
};

function showShadowRegion(area_id){
	var me = areaanalyzesAL;
	var veidoo = $("#veidoo").val();
	if(veidoo=='day'){
		analyse_date = $("#day").val();
	}else if(veidoo=='week'){
		analyse_date = $("#week").val();
	}else if(veidoo=='month'){
		analyse_date = $("#month").val();
	}
	$.ajax({
		url:appCtx+"base/report/AreaAnalyzes/showShadowRegion.html",
		type:"post",
		async : true,
		cache : false,
		data:{
			veidoo:veidoo,
			analyse_date:analyse_date,
			area_id:area_id
		},
		dataType:"json",
		success:function(datas){
				/*初始化条形图*/
				var xis = new Array();
				var series1 = new  Array();
				var series2 = new  Array();
				var area_name=null;
				$.each(datas,function(index,vo){
					xis.push(global.getToday(vo.analyse_date).split(" ")[0]);
					series1.push(Math.round(vo.vehicle_access_rate*Math.pow(10,2))/Math.pow(10,2));
					series2.push(Math.round(vo.vehicle_online_rate*Math.pow(10,2))/Math.pow(10,2));
				});
				var options = me.DoubleBarChart.option;
				options.xAxis[0].data=xis;
				options.series[0].data=series1;
				options.series[1].data=series2;
				me.DoubleBarChart.refash(options);   
		}
	});
}

function showpieChart(obj){
		var me = areaanalyzesAL;
		var option = me.PieChart.option;
		var datas =new Array();
		$("#noData").remove();
		if(obj!=null && obj!=''){
			if(obj.gpstime_exception_count!=0||obj.location_exception_count!=0||obj.head_exception_count!=0||obj.speed_160_count!=0){
				var valueArr = [obj.gpstime_exception_count,obj.location_exception_count,obj.head_exception_count,obj.speed_160_count];
				var nameArr = ['定位时间异常','经纬度异常','方向异常','速度>160'];
				for(var i=0;i<nameArr.length;i++){
					var map =new Object();
					map.name=nameArr[i];
					map.value=valueArr[i];
					datas.push(map);
				}
				option.legend.data=nameArr;
				option.series[0].data=datas;// [10, 52, 200, 334, 390, 330, 220];
				me.PieChart.refash(option);
			}else{
				global.noData("#pieChart");	
			}
		}else{
			global.noData('#pieChart');
		}
}
function selectveidoo(){
	var vo = $("#veidoo").val();
	if(vo=='day'){
		$("#day").show();
		$("#week").hide();
		$("#month").hide();
	}else if(vo=='week'){
		$("#day").hide();
		$("#week").show();
		$("#month").hide();
	}else if(vo=='month'){
		$("#day").hide();
		$("#week").hide();
		$("#month").show();
	}
}

function callback(veidoo,area_id,level,analyse_date,area_name){
	$("#veidoo").val(veidoo);
	$("#selectTypeSel").val(level);
	var name = $("#selectTypeSel").find("option:selected").text();
	$("#select2-selectTypeSel-container").text(name);
	if(veidoo=='day'){
		$("#day").show();
		$("#day").val(analyse_date);
		$("#week").hide();
		$("#month").hide();
	}else if(veidoo=='week'){
		$("#day").hide();
		$("#week").show();
		$("#week").val(analyse_date);
		$("#month").hide();
	}else if(veidoo=='month'){
		$("#day").hide();
		$("#week").hide();
		$("#month").show();
		$("#month").val(analyse_date);
	}
	areaanalyzesAL.initAreaList(level,area_name,area_id);
	areaanalyzesAL.queryTable(area_id,'');
}
